products=[("牛奶",5),("鸡蛋",20),("香蕉",10),("杯子",10)]
i=[]
money = float(input("请输入您的购物资金："))
while True:
    print("*"*100)
    print("商品列表如下:")
    for index,product in enumerate(products):
        print(f"{index+1}.商品{product[0]},价格{product[1]}")
    print("*"*100)
    a=input("请输入您要购买的商品（退出请键入q）：")
    if a.isdigit():
       a=int(a)
       if 0<= a-1 < len(products):
           b=products[a - 1]
           if b[1] <= money:
               i.append(b)
               money -= b[1]
               print("购买成功！")
           else:
               print(f"您的余额不足，金额为:{money}")
       else:
           print("您选的商品不存在！")
    elif a == "q":
        print("-"*10,"购物清单","-"*10)
        for x in i:
            print(f"已购商品：{x[0]},价格:{x[1]}")
        print("您的余额为:",money)
        break
    else:
        print("您的输入不合法")